package com.kingmed.kmss.bpmn.modules.backup.controller;


import com.kingmed.kmss.bpmn.flow.service.base.BpmCustomServiceImpl;
import com.kingmed.kmss.common.bo.bpmn.GroupBO;
import com.kingmed.kmss.common.bo.bpmn.GroupWithUserBO;
import com.kingmed.kmss.common.bo.bpmn.UserBO;
import com.kingmed.kmss.common.bo.bpmn.UserGroupBO;
import com.kingmed.kmss.common.utils.MessageUtils;
import com.kingmed.kmss.common.vo.CommonResponse;
import com.kingmed.kmss.common.vo.CommonResponseHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统管理，审批角色管理用到（去掉）
 * 同步、查询流程服务中用户
 * </p>
 */
@RestController
@RequestMapping("/ext")
@Api(tags = "bpmn-用户及组管理")
public class UserGroupController {

    @Autowired
    private BpmCustomServiceImpl bpmService;

   
    @ApiOperation("用户列表")
    @GetMapping(value = "/user")
    public CommonResponse<?> getUserList() {

        List<UserBO> userBOs = bpmService.getUserList();

        return CommonResponseHelper.success(userBOs);
    }
    
    @ApiOperation("创建用户")
    @PostMapping(value = "/user")
    public CommonResponse<?> createUser(@RequestBody UserBO userBO) {
        bpmService.createUser(userBO);
        
        return CommonResponseHelper.success(MessageUtils.message("user.created"));
    }
    
    @ApiOperation("删除用户")
    @PostMapping(value = "/user/delete")
    public CommonResponse<?> deleteUser(@RequestBody UserBO userBO) {
        bpmService.deleteUser(userBO);
        
        return CommonResponseHelper.success(MessageUtils.message("user.deleted"));
    }
    
    @ApiOperation("用户组列表")
    @GetMapping(value = "/group")
    public CommonResponse<?> getGroupList() {

        List<GroupWithUserBO> list = bpmService.getGroupList();
        return CommonResponseHelper.success(list);
    }
    
    @ApiOperation("创建用户组")
    @PostMapping(value = "/group")
    public CommonResponse<?> createGroup(@RequestBody GroupBO groupBO) {
        bpmService.createGroup(groupBO);
        
        return CommonResponseHelper.success(MessageUtils.message("group.created"));
    }
    
    @ApiOperation("删除用户组")
    @PostMapping(value = "/group/delete")
    public CommonResponse<?> deleteGroup(@RequestBody GroupBO groupBO) {
        bpmService.deleteGroup(groupBO);
        
        return CommonResponseHelper.success(MessageUtils.message("group.deleted"));
    }
    
    @ApiOperation("分配用户到用户组")
    @PostMapping(value = "/group/assignUser")
    public CommonResponse<?> assignUserToGroups(@RequestBody UserBO userBo) {
        bpmService.assignUserToGroups(userBo);
        
        return CommonResponseHelper.success(MessageUtils.message("userAssignedToGroup"));
    }
    
    @ApiOperation("从用户组中删除用户")
    @PostMapping(value = "/group/unAssignUser")
    public CommonResponse<?> unassignUserFromGroups(@RequestBody UserGroupBO userGroupBo) {
        bpmService.unassignUserFromGroups(userGroupBo);
        
        return CommonResponseHelper.success(MessageUtils.message("userUnassignedToGroup"));
    }
}
